<?php
use App\Models\AiModel as Model;
if($_GPC['op'] == 'del'){
	$cid = intval($_GPC['cid']);
	Model::where('id',$cid)->delete();
	die('1');
}elseif($_GPC['op'] == 'post'){
	$nid = intval(isset($_GPC['nid']) ? $_GPC['nid'] : 0);
	if ($_W['isajax']){
	    if (empty($_GPC['title'])) die('请输入模型名称');
	    if (empty($_GPC['model'])) die('请输入模型标识');
	    if (empty($_GPC['appkey'])) die('请输入模型秘钥');
		if ($nid > 0) $item = Model::find($nid);
		else $item = new Model();
		$item->title = trim($_GPC['title']);
		$item->model = $_GPC['model'];
		$item->appkey = $_GPC['appkey'];
		$item->save();
		die('1');
	}
	if ($nid > 0) $viewdata['item'] = Model::find($nid);
	else $viewdata['item'] = [];
}else{
	$viewdata['list'] = Model::orderBy('id','desc')->get();
}